import Vue from 'vue'
import {ValidationProvider,ValidationObserver, extend, localize} from 'vee-validate'
import {required} from 'vee-validate/dist/rules' // 验证规则导入

extend('required', required)
localize('zh_CN', {
    names: {
        phone: '手机号',
        code: '验证码'
    },
    messages: {
        required: (field) => `请输入${field}`,
    }
})

// 验证码
// 验证码
// 密码验证
extend('pwd', {
    validate(value) {
        return /^.*(?=.{6,})(?=.*\d).*$/.test(value)
    },
    message: '密码为6-16位'
})
// 手机号码是否满足要求
extend('mobile', {
    validate(value) {
        return /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1|8|9]))\d{8}$/.test(value)
    },
    message: '请填写正确的手机号'
})

Vue.component('ValidationProvider', ValidationProvider)
Vue.component('ValidationObserver', ValidationObserver)

